package com.blb.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blb.entity.IoMove;
import com.blb.entity.IoWarehouse;
import com.blb.service.IIoMoveService;
import com.blb.utils.DataTablePage;
import com.blb.utils.DataTablesPage;
import com.blb.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 仓库管理库存移库表 前端控制器
 * </p>
 *
 * @author xiaoxiong
 * @since 2020-05-20
 */
@Controller
@RequestMapping("/io-move")
public class IoMoveController {

    @Autowired
    private IIoMoveService moveService;

//分页列表
    @RequiresPermissions("storyyi")
    @ResponseBody
    @RequestMapping("/all")
    public DataTablesPage list(Integer draw,Integer start, Integer length) {
//        Page<IoMove> page = new Page<>(start, length);
//        page = moveService.page(page);
//        return new DataTablePage<IoMove>(page.getTotal(), page.getTotal(), page.getRecords());
        List<IoMove> ioMoves = moveService.movePage(draw, start, length);
        int count = moveService.count();
        return new  DataTablesPage(draw,count,count,ioMoves);
    }

    //移出的商品信息
    @RequiresPermissions("storyyi:opt")
    @ResponseBody
    @RequestMapping("/outAll")
    public List<Map> outAll(String pname,String ck){
        System.out.println("pname:"+pname);
        System.out.println("ck:"+ck);
        return moveService.outAll(pname,ck);
    }


    @RequiresPermissions("storyyi:opt")
    @ResponseBody
    @RequestMapping("/moveAdd")
    public Result moveAdd(@RequestParam Map map){
        System.out.println("移库的map:"+map);
         try {
             moveService.moveAdd(map);
             return new Result(true,"移库成功");
         }catch (Exception e){
             e.printStackTrace();
             return new Result(false,"移库失败");
         }
    }

}

